package cn.lll.vuehouse.aop;


import cn.lll.vuehouse.FORM.UserLoginForm;
import cn.lll.vuehouse.entity.Loginfo;
import cn.lll.vuehouse.service.LoginfoService;
import cn.lll.vuehouse.utils.IpUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;




//登录日志操作
@Component
@Aspect
public class LoginLogAspect {

    @Autowired
    private LoginfoService logInfoService;

    @AfterReturning(value = "execution(* cn.lll.vuehouse.controller.UserController.login(..))")
    public void afterLogin(JoinPoint joinPoint){

        UserLoginForm userLoginForm = (UserLoginForm) joinPoint.getArgs()[0];
        HttpServletRequest httpServletRequest = (HttpServletRequest) joinPoint.getArgs()[1];
        String username = userLoginForm.getUsername();



        Loginfo logInfo = new Loginfo();
        logInfo.setUsername(username);
        logInfo.setIp(IpUtil.getRequestClientRealIp(httpServletRequest));

        logInfo.setParams("机密");
        logInfo.setUrl("机密");
        logInfo.setModel("个人专属无敌登录日志");
        logInfo.setDescription("亮瞎钛合金狗眼帅气登录");
        logInfoService.save(logInfo);

    }
}
